﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Text;
using System.Web;

namespace UCHENG.FILEHASH.UTILS
{
    public class HttpService
    {
        private const string API_PLAYER_GROUPS = "http://esp-developer-service.edu.web.sdp.101.com/v0.1/players/{0}/versions/{1}/groups";

        public static string getPlayerUrl(string playerCode, string version)
        {
            string url = String.Format(API_PLAYER_GROUPS, playerCode, version);

            return HttpService.get(url, "utf-8");
        }


        private const string API_MODULE_LIST = "http://esp-developer-service.edu.web.sdp.101.com/v0.1/heaps/{0}/versions/{1}";

        public static string getModuleList(string playerCode, string version)
        {
            string url = String.Format(API_MODULE_LIST, playerCode, version);
            return HttpService.get(url, "utf-8");
        }

        private static string get(string Url, string type)
        {
            try
            {
                System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
                // Get the response instance.
                System.Net.WebResponse wResp = wReq.GetResponse();
                System.IO.Stream respStream = wResp.GetResponseStream();
                // Dim reader As StreamReader = New StreamReader(respStream)
                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type)))
                {
                    return reader.ReadToEnd();
                }
            }
            catch (System.Exception ex)
            {
                //errorMsg = ex.Message;
            }
            return "";
        }

    }
}